package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.ProductModel;
import dao.Products;

public class Menu extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		HttpSession sessionLoai = request.getSession();
		HttpSession sessionDip = request.getSession();
		
		String danhmuc = request.getParameter("danhmuc");
		
		List<ProductModel> rs = new ArrayList<ProductModel>();
		Products productDTO = new Products();
		if(danhmuc.equals("loai")){
			String maloai = request.getParameter("maloai");
			rs = productDTO.getProducts(null, null, maloai, null);
			if(rs.size() == 0) return;
			sessionLoai.setAttribute("listhoaDM", rs.get(0));
		}
		else {
			if(danhmuc.equals("dip")){
				String dip = request.getParameter("dip");
				rs = productDTO.getProducts(null, null, null, dip);
				if(rs.size() == 0) return;
				sessionDip.setAttribute("listhoaDM", rs.get(0));
				
			}
		}
		response.sendRedirect("Trang_danh_muc.jsp");
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
}
